package userroute

import (
	"itodo/core/common/errorcode"
	"itodo/core/dao/teamdao"
	"itodo/core/service/users"

	"github.com/RocksonZeta/irisx"
	"github.com/RocksonZeta/wrap/errs"
	"github.com/kataras/iris/v12"
)

type User struct {
	Id   int
	Name string
}

//RouteUserApi /api/user
func RouteApiUser(party iris.Party) {
	party.Get("/", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		uid := c.GetUidInt()
		if uid == 0 {
			panic(errs.NewUserError(errorcode.UserNoSignin, "user not signin"))
		}
		u := users.Users{}.Get(uid)
		c.Ok(u)
	})
	party.Post("/", func(ctx iris.Context) {
		c := ctx.(*irisx.Context)
		param := teamdao.TeamUsersAddParam{}
		param.TeamId = c.CheckBody("teamId").NotEmpty().Int(0)
		param.Role = c.CheckBody("role").NotEmpty().Int(0)
		param.Uid = c.GetUidInt()
		r := teamdao.TeamUsers{}.Add(param)
		c.Ok(r)
	})
}
